package com.mall.action;

import com.github.pagehelper.PageInfo;
import com.mall.bean.Permission;
import com.mall.bean.QueryWhereVO;
import com.mall.service.PermissionService;
import com.mall.uitl.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lwd1513
 * @date 2022-04-28 18 32
 * discription
 */
@RestController
@RequestMapping("PermissionController")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @RequestMapping("query")
    public JsonUtil query(QueryWhereVO queryWhereVO, Permission permission){
        JsonUtil jsonUtil = new JsonUtil();
        String currentPage = queryWhereVO.getCurrentPage();
        String pageSize = queryWhereVO.getPageSize();
        PageInfo<Permission> permissionPageInfo = permissionService.queryDataByPage(Integer.parseInt(currentPage), Integer.parseInt(pageSize), permission);
        jsonUtil.setData(permissionPageInfo);
        return jsonUtil;
    }

    //deletePermissionById
    @RequestMapping("deletePermissionById/{permission_id}")
    public JsonUtil deletePermissionById(@PathVariable("permission_id") Integer permission_id){
        JsonUtil jsonUtil = new JsonUtil();
       int res = permissionService.deletePermissionById(permission_id);
        jsonUtil.setMsg("删除成功");
        return jsonUtil;
    }

    //updatePermissionById
    @RequestMapping("updatePermissionById")
    public JsonUtil updatePermissionById(Permission permission){
        JsonUtil jsonUtil = new JsonUtil();
        int res = permissionService.updatePermissionById(permission);
        jsonUtil.setMsg("修改成功");
        return jsonUtil;
    }
}
